/**
 *@description:TODO
 * @author: cai
 *@time:2017年7月3日下午4:24:39
 */
package com.pos.modules.inquery.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.pos.R;
import com.pos.modules.inquery.bean.BillGoodsBean;
import com.pos.toolbox.FinancialUtils;

import java.util.List;

/**
 * @description:订单详情商品list adapter
 * @author cai
 * @time:2017年7月3日下午4:24:39
 */
public class BillGoodsListAdapter extends ArrayAdapter<BillGoodsBean> {

	public BillGoodsListAdapter(Context context, List<BillGoodsBean> goodsList) {
		super(context, 0, goodsList);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			convertView = LayoutInflater.from(getContext()).inflate(R.layout.bill_detail_item_layout, null);
			holder = new ViewHolder();
			holder.text_num = (TextView) convertView.findViewById(R.id.text_num);
			holder.text_name = (TextView) convertView.findViewById(R.id.text_name);
			holder.text_count = (TextView) convertView.findViewById(R.id.text_count);
			holder.text_amount = (TextView) convertView.findViewById(R.id.text_amount);
			convertView.setTag(holder);

		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		BillGoodsBean item = getItem(position);
		String index;
		if (position < 9) {
			index = "0" + (position + 1);
		} else {
			index = "" + (position + 1);
		}
		holder.text_num.setText(index + ".");
		holder.text_name.setText(item.getGoodsName());
		// holder.text_price.setText(FinancialUtils.fenToYuan(item.getPrice()));
		holder.text_count.setText(FinancialUtils.fenToYuan(item.getPrice()) + " X" + item.getCount());
		holder.text_amount.setText(FinancialUtils.fenToYuan(item.getAmount()));

		return convertView;
	}

	static class ViewHolder {
		public TextView text_num, text_name, text_count, text_amount;
	}

}
